import unittest
from tower import *
from game_elements import *

SPEED = 1
DEFENCE = 2
HP = 100
POS = (40,50)

class TestTDGame(unittest.TestCase):
    def setUp(self):
        self.m = Monster(HP, defence = DEFENCE, speed = SPEED, position = POS, goal = {'pos':(0,0), 'id':0})

    def test_tower(self):
        t = Tower(0,0,0,0, (0,0))
        self.assertTrue(t.gunshot == t.firepower == t.cd == t.level == 0)
        #self.assertRaises(AttributeError, lambda: t.attack())

    def test_monster(self):        
        m = self.m
        self.assertTrue(m.hp == m.MAX_HP == HP)
        self.assertTrue(m.defence == DEFENCE and m.speed() == SPEED and m.position == POS)

    def test_monster__dead(self):
        m = self.m
        m.hp = 0
        self.assertTrue(m.dead())

    def test_monster__attack_by(self):
        m = Monster(HP, defence = 0, speed = 0, position = (0,0), goal = {'pos':(0,0), 'id':0})
        self.assertFalse(m.dead()) 
        m.attacked_by(HP)
        self.assertTrue(m.dead())

    def test_monster__direction_of_2pos(self):
        a, b, c, d = (0,0), (10,0), (10,20), (0,20)
        f = Monster.direction_of_2pos
        self.assertEqual(f(a,b), (1,0))
        self.assertEqual(f(c,d), (-1,0))
        self.assertEqual(f(b,c), (0,1))



if __name__ == '__main__':
    unittest.main()